package com.zb.controller;


import com.zb.entity.dto.WxTemplateDto;
import com.zb.entity.dto.WxTemplateSelectDto;
import com.zb.result.Result;
import com.zb.service.ZjAdmWxTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台微信消息模板库表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-11
 */
@Api(tags = "微信消息模板类接口")
@RestController
@RequestMapping("/wxTemplate")
public class ZjAdmWxTemplateController {
    @Autowired
    private ZjAdmWxTemplateService wxTemplateService;

    @ApiOperation(value = "新增或修改微信消息模板")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid WxTemplateDto wxTemplateDto) {
        wxTemplateService.save(wxTemplateDto);
        return Result.success(null == wxTemplateDto.getId()? "新增微信消息模板成功" : "修改微信消息模板成功");
    }

    @ApiOperation(value = "微信消息模板列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody WxTemplateSelectDto templateSelectDto) {
        return Result.success("获取微信消息模板列表成功").data(wxTemplateService.getList(templateSelectDto));
    }

    @ApiOperation(value = "根据模板ID获取详情")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable @ApiParam(value = "微信模板ID", required = true) Long id) {
        return Result.success("获取微信消息模板详情成功").data("row", wxTemplateService.getInfoById(id));
    }

    @ApiOperation(value = "批量禁用或启用微信模板")
    @PutMapping("/disabled")
    public Result disabled(@RequestParam @ApiParam(value = "是否禁用：false-否，true-是", required = true) boolean disable,
                           @RequestBody @ApiParam(value = "微信模板ID集合", required = true) List<Long> idList) {
        wxTemplateService.batchDisabled(idList, disable);
        return Result.success(disable? "禁用微信消息模板成功" : "启用微信消息模板成功");
    }



}
